Other: Interrupted TS/ARFIMA/Spectral Analysis

1. Interrupted Time Series

Given the profound disruptions caused by the COVID-19 pandemic, which has significantly interrupted daily life and global events, employing an interrupted time series analysis is particularly apt. This method allows us to quantitatively assess the pandemic’s impact on key socio-economic indicators. In our project, we have chosen to focus on Pfizer stock prices and GDP per capita as two pivotal metrics. By analyzing these indicators, we aim to capture and understand the extent of COVID-19’s effects on both the corporate sector, specifically pharmaceuticals, and broader economic health. This approach will enable us to isolate the direct impacts of the pandemic from other variables and gain insights into the resilience and responsiveness of different economic sectors during such global crises. In these examples, we all selected 2020 February 20th as the treatment date to research.

1.1 GDP Per Capita

Code
gdp <- read_csv('Datasets/gdp.csv')

# Convert DATE column from m/d/yy format to Date object and reformat to "Year" only for simplicity
gdp$DATE <- format(mdy(gdp$DATE), "%Y/%m/%d")

# Convert GDP column to numeric (floating-point) format if not already
gdp$GDP <- as.numeric(gdp$GDP)

# Visualize the plot
start_year <- year(min(gdp$DATE))
start_month <- month(min(gdp$DATE))
end_year <- year(max(gdp$DATE))
end_month <- month(max(gdp$DATE))

# Calculate the number of observations from start to end
num_obs <- (end_year - start_year) * 4 + ceiling((end_month - start_month) / 3)


# data glimpse
head(gdp, 3)
# A tibble: 3 × 2
  DATE          GDP
  <chr>       <dbl>
1 2017/01/01 19280.
2 2017/04/01 19439.
3 2017/07/01 19693.
Code
fig <- plot_ly(gdp, x = ~DATE, y = ~GDP,name = 'GDP Per Capita', type = 'scatter', mode = 'lines')

fig
Code
# Create the time series object
#gdp_ts <- ts(gdp$GDP, start = c(start_year, start_month), frequency = 4, deltat = 0.25)

dataTS <-data.frame("Y"=gdp$GDP)
dataTS$Ts<-seq(1:length(gdp$GDP))
dataTS$D <- ifelse(gdp$DATE < as.Date("2020-02-20"), 0, 1)
dataTS$P<- seq_along(gdp$DATE)
dataTS$P[gdp$DATE < as.Date("2020-02-20")] <- 0

head(dataTS)
         Y Ts D P
1 19280.08  1 0 0
2 19438.64  2 0 0
3 19692.60  3 0 0
4 20037.09  4 0 0
5 20328.55  5 0 0
6 20580.91  6 0 0
Code
index_of_2020_02_20 <- which(gdp$DATE == as.Date("2020-04-01"))
#index_of_2020_02_20 #14

plot( dataTS$Ts, dataTS$Y,
      bty="n", pch=19, col="gray",
      xlab = "Time", 
      ylab = "GDP Per Capita" )

# Line marking the interruption
abline( v=13, col="firebrick", lty=2 )
text( 9, 24000, "Start of COVID", col="firebrick", cex=1.3, pos=4 )

# Add the regression line
ts <- lm( Y ~ Ts + D + P, data=dataTS )
lines( dataTS$Ts, ts$fitted.values, col="steelblue", lwd=2 )

  • Pre-COVID Trend: Prior to the dashed red line labeled “Start of COVID,” there is a positive trend in GDP per capita, indicating economic growth. This is represented by the blue line, which is the fitted line from a regression model, showing the upward trajectory of GDP per capita over time.

  • COVID-19 Impact: The dashed red line signifies the point at which the COVID-19 pandemic began. Following this line, there’s a noticeable dip in GDP per capita, reflecting the immediate economic impact of the pandemic. This downturn signifies a break from the previous growth trend.

  • Post-COVID Recovery: After the initial dip, the blue fitted line indicates that GDP per capita began to recover, continuing on an upward trajectory, although starting from a lower point than where the pre-COVID trend would have predicted.

  • Recovery Trend: The post-COVID section of the blue line is steeper than the pre-COVID section, suggesting that the rate of growth in GDP per capita after the initial pandemic shock may be faster than the growth rate before the pandemic.

Code
stargazer( ts, 
           type = "text", 
           dep.var.labels = ("GDP Per Capita"),
           column.labels = ("Model results"),
           covariate.labels = c("Time", "Treatment", "Time Since Treatment"),
           omit.stat = "all", 
           digits = 2 )

================================================
                         Dependent variable:    
                     ---------------------------
                           GDP Per Capita       
                            Model results       
------------------------------------------------
Time                          224.26***         
                               (23.05)          
                                                
Treatment                   -5,566.75***        
                              (438.41)          
                                                
Time Since Treatment          306.49***         
                               (29.61)          
                                                
Constant                    19,112.23***        
                              (182.95)          
                                                
================================================
================================================
Note:                *p<0.1; **p<0.05; ***p<0.01

The interrupted regression result presented describes the impact of the onset of the COVID-19 pandemic on GDP per capita over time. Here’s a detailed breakdown of the model’s components and the statistical outputs:

  • Time (Ts): The coefficient of 224.26 (with a standard error of 23.05) and significance indicated by three asterisks (***), suggesting a p-value less than 0.01, indicates that for every unit increase in time, the GDP per capita increases by approximately 224.26 units, assuming no treatment and not considering the passage of time since the treatment. This shows a general trend of GDP growth over time under normal circumstances.

  • Treatment (D): The treatment effect is -5,566.75 (with a standard error of 438.41), also highly significant (***). This suggests that the introduction of the treatment (the onset of the pandemic) leads to an immediate drop in GDP per capita by approximately 5,566.75 units. This captures the initial shock of the event on the economy.

  • Time Since Treatment (P): The coefficient of 306.49 (with a standard error of 29.61) and significance (***), indicates that for each unit of time after the treatment, GDP per capita increases by about 306.49 units. This represents a recovery trajectory where, after the initial shock, GDP per capita begins to recover at this rate.

In summary, the model indicates that while the treatment had a significant negative impact on GDP per capita, there has been a subsequent positive rate of recovery over time following the initial shock. This provides a quantified insight into the economic impact of the event and its aftermath.

1.2 Stock Price

Code
# Set options to suppress warnings
options("getSymbols.warning4.0" = FALSE)
options("getSymbols.yahoo.warning" = FALSE)

# Define the tickers
tickers <- c("PFE")

# Loop through tickers to get stock data
for (ticker in tickers) {
  getSymbols(ticker,
             from = "2016-01-01",
             to = "2024-01-01")
}

# Create a data frame with adjusted closing prices
stock <- data.frame(date = index(PFE), value = Ad(PFE))

# data glimpse
head(stock, 3)
                 date PFE.Adjusted
2016-01-04 2016-01-04     22.07899
2016-01-05 2016-01-05     22.23794
2016-01-06 2016-01-06     21.84404
Code
fig <- plot_ly(stock, x = ~date, y = ~PFE.Adjusted,name = 'Pfizer Stock Price', type = 'scatter', mode = 'lines')

fig
Code
dataTS <-data.frame("Y"=stock$PFE.Adjusted)
dataTS$Ts<-seq(1:length(stock$PFE.Adjusted))
dataTS$D <- ifelse(stock$date < as.Date("2020-02-20"), 0, 1)
dataTS$P<- seq_along(stock$date)
dataTS$P[stock$date < as.Date("2020-02-20")] <- 0

head(dataTS)
         Y Ts D P
1 22.07899  1 0 0
2 22.23794  2 0 0
3 21.84404  3 0 0
4 21.69892  4 0 0
5 21.42250  5 0 0
6 21.47087  6 0 0
Code
index_of_2020_02_20 <- which(stock$date == as.Date("2020-02-20"))
#index_of_2020_02_20 #1040

plot( dataTS$Ts, dataTS$Y,
      bty="n", pch=19, col="gray",
      xlab = "Time (days)", 
      ylab = "Pfizer Stock Price" )

# Line marking the interruption
abline( v=1039, col="firebrick", lty=2 )
text( 700, 40, "Start of COVID", col="firebrick", cex=1.3, pos=4 )

# Add the regression line
ts <- lm( Y ~ Ts + D + P, data=dataTS )
lines( dataTS$Ts, ts$fitted.values, col="steelblue", lwd=2 )

  • Trend Before COVID-19: Before the dashed red vertical line that denotes the start of COVID-19, there is a blue line indicating a general upward trend in Pfizer’s stock price. This suggests that Pfizer’s stock was gradually increasing in value over time before the pandemic began.

  • Start of COVID-19: The dashed red vertical line indicates the point at which the COVID-19 pandemic started. This is a crucial time marker for the analysis.

  • Trend After COVID-19: After the start of COVID-19, the plot shows significant volatility in Pfizer’s stock price. The stock price initially follows the pre-pandemic trend and continues to increase but then shows some fluctuation before sharply rising. This sharp rise could be due to various factors, potentially including positive news about vaccine development or other pharmaceutical advances related to COVID-19 made by Pfizer.

  • Overall Pattern: Towards the right end of the plot, after a peak, there is a noticeable decline in the stock price, which may indicate a period of correction or response to other market or global factors.

Code
stargazer( ts, 
           type = "text", 
           dep.var.labels = ("Pfizer Stock Price"),
           column.labels = ("Model results"),
           covariate.labels = c("Time", "Treatment", "Time Since Treatment"),
           omit.stat = "all", 
           digits = 2 )

================================================
                         Dependent variable:    
                     ---------------------------
                         Pfizer Stock Price     
                            Model results       
------------------------------------------------
Time                           0.01***          
                               (0.001)          
                                                
Treatment                      2.29**           
                               (0.92)           
                                                
Time Since Treatment          -0.002***         
                               (0.001)          
                                                
Constant                      21.56***          
                               (0.31)           
                                                
================================================
================================================
Note:                *p<0.1; **p<0.05; ***p<0.01

The regression results presented show impact of the onset of the COVID-19 pandemic on the stock price of Pfizer. The regression model includes variables for time, treatment, and the time since treatment was introduced. Here’s a breakdown of each component of the output:

  • Time (Ts): The coefficient for time is 0.01 with a p-value of less than 0.01 (indicated by ***), suggesting that it is highly statistically significant. This implies that, on average, the stock price of Pfizer has been increasing by 0.01 units each time unit regardless of other factors in the model.

  • Treatment (D): The treatment variable has a coefficient of 2.29 with a p-value of less than 0.05 (**), indicating a statistically significant positive effect on the Pfizer stock price. This suggests that the onset of the COVID-19 pandemic led to an average increase in Pfizer’s stock price by 2.29 units at the time of the treatment’s implementation.

  • Time Since Treatment (P): The coefficient for time since treatment is -0.002 with a p-value of less than 0.01 (***), which is highly significant. This indicates that following the treatment, the stock price decreases by an average of 0.002 units per time unit. This could suggest that the initial positive impact of the treatment diminishes over time.

The model suggests that the Pfizer stock price has a general upward trend over time. There was a significant increase in the stock price at the time of treatment, which means the investment of COVID-19 vaccinates could be helpful for the stock price during some periods of COVID-19. However, the effect of COVID-19 diminishes slightly over time, indicating that while the intervention had a positive immediate impact, its effect lessens as time progresses.